<?php
namespace Home\Controller;
use Common\Controller\MyInitController;
class RegisterController extends MyInitController {

    

    public function register(){
        $openid=$this->getOpenId();
        echo $openid;
    	layout(false);
        $openid=isset($_GET['openid'])?I('get.openid'):'';
        session('openid',$openid);
        //$this->display();

    }

    public function to_get_register(){
        $openid=$this->getOpenId();
        //$openid=7777;
    	$register_number=I('post.number');
    	$register_passwd=I('post.passwd');
        if($register_passwd==NULL)
        {
           // echo "请输入密码";
            $this->error("请输入密码");
        }
        else if($register_number==NULL)
        {
           // echo "请输入学号";
            $this->error("请输入学号");
        }
    	//var_dump($register_number);
    	//var_dump($register_passwd);
    	$md5_register_passwd=md5($register_passwd);
        $Inf=M("user_information");
        $check=$Inf->where("number='{$register_number}' OR openid='{$openid}'")->find();
        if($check)
            $this->error('该学号已注册');
    	if ($register_number!=NULL) {
    		
            $data['username'] = "初级用户";
            $data['openid'] = $openid;
            $data['number'] = $register_number;
            $data['passwd'] = $md5_register_passwd;
            $result=$Inf->data($data)->add();
            if($result)
            {
                echo "注册成功,点击<退回微信界面";
               // var_dump(session('111'));
            }
            else
                echo "注册失败";
    	}
    	else{
    		echo "undefined error";
    	}
    }

    public function detail_register(){
        layout(false);
        $openid=$this->getOpenId();
        $Reg= M("user_information");
        $number=$Reg->where("openid='{$openid}'")->getField('number'); 
        //echo $number;
        $this->assign('number',$number);
        $this->display('register_detail');
    }

    public function detail_get_register(){
        $openid=$this->getOpenId();

        //$openid=$this->getOpenId();
        //$openid=7777;
        //$openid=123581;
        $register_name=I('post.name');
        $register_class=I('post.class');
        $register_email=I('post.email');
        $data['username'] = $register_name;
        $data['class'] = $register_class;
        $data['email'] = $register_email;
        $Inf=M("user_information");
        $result=$Inf->where("openid='{$openid}'")->save($data);
        if($result)
            echo "更新成功";
    }



}